
<div class="span12">
            <h1 class="page-title">新闻列表</h1>
<div class="btn-toolbar">
    <a href="index.php?c=news&a=add&admin=1" class="btn btn-primary"><i class="icon-plus"></i> 新闻添加</a>
    <button class="btn tr_add">增加一行</button>
    <button class="btn">Export</button>
  <div class="btn-group">
  </div>
</div>
<div class="well">
    <form action="index.php?c=news&a=add&admin=1" method="post" accept-charset="utf-8">
            <table class="table">
                <select name="a" style="width:100px;">
                    <option value="0">请选择</option>
                    <option value="sta">审核通过</option>
                    <option value="del">删除</option>
                </select>
                <input type="button" class="sub" value="提交">
                <thead>
                    <tr>
                      <th><input type="checkbox" class="all_ck" value="">全选</th>
                      <th>编号</th>
                      <th>标题</th>
                      <th>类型</th>
                      <th>作者</th>
                      <th>上传者</th>
                      <th>缩略图</th>
                      <th>内容</th>
                      <th>审核状态</th>
                      <th>上传时间</th>
                    </tr>
                </thead>
                <tbody>
                    <?php foreach($data as $v){ ?>
                        <tr>
                            <td><input type="checkbox" class="check" name="id" value="<?php echo $v['id'];?>"></td>
                            <td filed="id"> <?php echo $v['id'];?> </td>
                            <td filed="title" class="edit" > <?php echo mb_substr($v['title'],0,10).'...';?> </td>
                            <td filed="type" class="edit"> <?php echo $v['name'];?> </td>
                            <td> <?php echo $v['author'];?> </td>
                            <td> <?php echo $v['send_user'];?> </td>
                            <td> <img src="<?php echo empty($v['url'])?'./uploads/none.jpg':$v['url'];?>" style="width: 50px;height: 50px;" /> </td>
                            <td> <?php echo mb_substr($v['content'],0,12).'...';?> </td>
                            <td> <?php echo ($v['status'])?'已审核':'未审核';?> </td>
                            <td> <?php echo $v['create_time'];?> </td>
                            <td> <a href="index.php?c=news&a=edit&admin=1&id=<?php echo $v['id'];?>">编辑<i class="icon-pencil"></i></a> </td>
                            <td> <a href="index.php?c=news&a=del&admin=1&id=<?php echo $v['id'];?>" role="button" onclick="return confirm('请确认是否真的要删除？')">删除<i class="icon-remove"></i></a> </td>

                        </tr>
                <?php } ?>

                </tbody>

            </table>
        </form>
    </div>
    <div class="pagination">
    <ul>
         <?php echo $pages; ?>
    </ul>

    <script src="resources/admin/js/jQuery.js" type="text/javascript"></script>
    <script type="text/javascript">

    $(function(){
    //无刷翻页
        $('.pagination').on('click','li',function(){

          var url = $(this).find('a').attr('href');

          $.ajax({
            type:'get',
            url:url,
            dataType:'json',
            //data:'',
            //async:false,
            success:function(json){

              var data = json['data'];

              var html = '';
              for(var i in data){
                  html +='<tr>';
                  html +='<td><input type="checkbox" class="check" name="id" value="'+data[i].id+'"></td>';
                  html +='<td filed="id"> '+data[i].id+' </td>';
                  html +='<td filed="title" class="edit"> '+data[i].title.substring(0,5)+' </td>';
                  html +='<td filed="type" class="edit"> '+data[i].name+' </td>';
                  html +='<td> '+data[i].author+' </td>';
                  html +='<td> '+data[i].send_user+' </td>';
                  var url = data[i].url!=null?data[i].url:'./uploads/none.jpg';
                  html +='<td> <img src="'+url+'" style="width:50px;height=50px;" /> </td>';
                  html +='<td> '+data[i].content.substring(0,10)+' </td>';
                  var status = (data[i].status != 0)?'已审核':'未审核';
                  html +='<td>'+status+'</td>';
                  html +='<td>'+data[i].create_time+'</td>';
                  html +='<td> <a href="index.php?c=news&a=edit&admin=1&id='+data[i].id+'">编辑<i class="icon-pencil"></i></a> </td>';
                  html +='<td> <a href="index.php?c=news&a=del&admin=1&id='+data[i].id+'" role="button" onclick="return confirm(请确认是否真的要删除？)">删除<i class="icon-remove"></i></a> </td>';
                  html +='</tr>';
              };

              $('tbody').html(html);

              $('.pagination ul').html(json['pages']);
            }

          });

          return false;
        });
    //双击修改
        $('tbody').on('dblclick','.edit',function(event) {

          if($('tbody :text').length > 0){

            var txt = $('tbody :text').val();
            $('tbody :text').parent().text(txt);

          };

           var txt = $(this).text();

           var inp ='<input type="text" style="width:80px;height=12px;" value="'+txt+'">';
           $(this).html(inp);

           $('tbody :text').focus();



            $('tbody :text').blur(function(){

              var id = $(this).parent().parent().find('td:first').text();
              var filed = $(this).parent().attr('filed');
              //alert(filed);

              var val = $(this).val();
              $(this).parent().text(val);
              $.ajax({
                url: 'index.php?c=news&a=edit&admin=1',
                type: 'POST',
                data: {'id': id,'filed':filed,'val':val},
                  success:function(row){
                    if (row > 0){
                        alert('修改成功');
                    }else{
                        alert('修改失败');
                    };
                    //console.log(row);
                  }
              });

            });

        });
    //增加一行功能
        $('.tr_add').click(function(){

            var html = '';
            html +='<tr class="tr_new">';
            html +='<td><input type="checkbox" name="" value=""></td>';
            html +='<td filed="id"></td>';
            html +='<td filed="title" class="edit"><input type="text" style="width:100px;" name="title" value=""></td>';
            html +='<td filed="type" class="edit select"><select style="width:100px;" class="pid" name="type">';
            html +='<option >—— ——</option>';
            html +='<option value="1">国内新闻</option>';
            html +='<option value="2">国外新闻</option>';
            html +='</select></td>';
            html +='<td><input type="text" style="width:100px;" name="author"></td>';
            html +='<td></td>';
            html +='<td></td>';
            html +='<td><textarea name="content"></textarea></td>';
            html +='<td><select style="width:100px;" name="status">';
            html +='<option value="0">未审核</option>';
            html +='<option value="1">已审核</option>';
            html +='</select></td>';
            html +='<td></td>';
            html +='<td><input type="submit" name="" value="提交"></td>';
            html +='<td> <a class="cancle">取消<i class="icon-remove"></i></a> </td>';
            html +='</tr>';

            $('tbody').append(html);

            $('.cancle').click(function(){
                $('.tr_new').remove();
            })


        })
    // 增加一行中的类型搜索
        $('tbody').on('change','.pid',function(){

          $(this).nextAll().remove();


          //var v1 = $(this).find('option:selected').text();
          var v1 = $(this).get(0).selectedIndex;
          if (v1=='0') {

              return false;
          };
          var pid = $(this).val();

          $.ajax({
            url: 'index.php?c=news&a=add&admin=1',
            type: 'post',
            dataType: 'json',
            data: {'pid': pid},
            success:function(json){
              //console.log(json);
              var html = '<br><select class="pid" style="width:100px;" name="pid">';
              html += '<option value="">—— ——</option>';
              for(var i in json){

                html += '<option value="'+json[i].id+'">'+json[i].name+'</option>';

              }

              html += '</select>';
              //console.log(html);
              $('.select').append(html);

            }
          })


        })
    //全选功能
        $('.all_ck').click(function(){
            var ck = $(this).prop('checked');
            $('.check').prop('checked', ck);
        })

    //批量删除与审核
        $('.sub').click(function(){

            var a = $('select[name="a"]').val();
            if(a == 0){
                alert('请先选择要执行的操作');
                return false;
            }else{
                var url = 'index.php?c=news&admin=1&a='+a;
            }
            var id = [];
            var i = 0;

            $('.check:checked').each(function(){

                id[i] = $(this).val();
                i++;

            })
            //console.log(id);return false;
            $.ajax({
                url: url,
                type: 'POST',
                //dataType: 'default: Intelligent Guess (Other values: xml, json, script, or html)',
                data: {id: id},
                success:function(json){

                    if (json > 0) {
                        alert("操作成功！");self.location.href="index.php?c=news&a=list&admin=1";
                    }else{
                        alert("操作失败！");
                    }

                }
            })

        })

    });

    </script>

    <!-- <div class="modal small hide fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
            <h3 id="myModalLabel">警示！</h3>
        </div>
        <div class="modal-body">
            <p class="error-text"><i class="icon-warning-sign modal-icon"></i>确定真的删除该条新闻吗？</p>
        </div>
        <div class="modal-footer">
            <button class="btn" data-dismiss="modal" aria-hidden="true">取消</button>
            <a href="index.php" class="btn btn-danger" data-dismiss="modal">删除</a>
        </div>
    </div> -->
</div>


